/* eslint-disable no-underscore-dangle */
/* eslint-disable max-classes-per-file */
import { JsonProperty, Serializable } from '@/plugins/reflect-metadata';

import { OrderDetailStatusType } from '../const';

@Serializable()
export default class CardOrderItem {
  @JsonProperty('productCode')
    productCode: number = 0;

  @JsonProperty('cardProductName')
    cardProductName: string = '';

  @JsonProperty('imageUrl')
    imageUrl: string = '';

  @JsonProperty('customOrderNo')
    customOrderNo: string = '';

  @JsonProperty('customCreateTime')
    customCreateTime: string = '';

  @JsonProperty('cardFacevalue')
    cardFacevalue: number = 0;

  @JsonProperty('recycleRate')
    recycleRate: number = 0;

  @JsonProperty('totalCount')
    totalCount: number = 0;

  @JsonProperty('totalAmount')
    totalAmount: number = 0;

  @JsonProperty('successAmount')
    successAmount: number = 0;

  @JsonProperty('totalStatus')
    totalStatus: string = '';
}

@Serializable()
export class CardOrderDetailVoItem {
  @JsonProperty('orderNo')
    orderNo: string = '';

  @JsonProperty('batchNo')
    batchNo: string = '';

  @JsonProperty('cardSn')
    cardSn: string = '';

  @JsonProperty('cardFacevalue')
    cardFacevalue: number = 0;

  @JsonProperty('recycleRate')
    _recycleRate: number = 0;

  get recycleRate() {
    const rateSplit = `${this._recycleRate}`.split('.');
    let rate = '';
    if (rateSplit[1].length >= 4) {
      rate = `${rateSplit[1]}`;
    }
    if (rateSplit[1].length === 3) {
      rate = `${rateSplit[1]}0`;
    }
    if (rateSplit[1].length === 2) {
      rate = `${rateSplit[1]}00`;
    }
    if (rateSplit[1].length === 1) {
      rate = `${rateSplit[1]}000`;
    }

    if (rate.slice(2).length > 0) {
      return `${[...rate.slice(0, 2), '.', ...rate.slice(2)].join('')}折`;
    }
    return `${[...rate.slice(0, 2)].join('')}折`;
  }

  @JsonProperty('actualAmount')
    actualAmount: number = 0;

  @JsonProperty('status')
    status: number = 0;

  @JsonProperty('remark')
    remark: string = '';

  @JsonProperty('createTime')
    createTime: string = '';

  @JsonProperty('updateTime')
    updateTime: string = '';

  get cardInfo() {
    return {
      orderNo: this.orderNo,
      cardSn: this.cardSn,
      cardFacevalue: `${this.cardFacevalue.toFixed(2)}元`,
      recycleRate: `${this.recycleRate}`,
      status:
        this.status === OrderDetailStatusType.成功 || this.status === OrderDetailStatusType.处理中
          ? OrderDetailStatusType[this.status]
          : this.remark,
    };
  }
}

@Serializable()
export class CardOrderDetailItem {
  @JsonProperty('productCode')
    productCode: number = 0;

  @JsonProperty('cardProductName')
    cardProductName: string = '';

  @JsonProperty('imageUrl')
    imageUrl: string = '';

  @JsonProperty('customOrderNo')
    customOrderNo: string = '';

  @JsonProperty('customCreateTime')
    customCreateTime: string = '';

  @JsonProperty('cardFacevalue')
    cardFacevalue: number = 0;

  @JsonProperty('totalCount')
    totalCount: number = 0;

  @JsonProperty('totalAmount')
    totalAmount: number = 0;

  @JsonProperty('successAmount')
    successAmount: number = 0;

  @JsonProperty('totalStatus')
    totalStatus: string = '';

  @JsonProperty({ name: 'cardOrderDetailVoList', type: CardOrderDetailVoItem })
    cardOrderDetailVoList: CardOrderDetailVoItem[] = [];

  get cardInfo() {
    return {
      customOrderNo: this.customOrderNo,
      cardFacevalue: `${this.cardFacevalue.toFixed(2)}元`,
      actualAmount: `${this.successAmount.toFixed(2)}元`,
      recycleRate: `${this.cardOrderDetailVoList[0].recycleRate}`,
      createTime: this.customCreateTime,
      endTime: this.customCreateTime,
    };
  }
}
